import java.util.Arrays;
import java.lang.*;

public class ArrayTest {
    public static void main(String[] args) {
        int[][] arr1 = new int[][]{{1, 2, 3}, {4, 5, 6}};
//        int[][] arr2 = new int[2][3]{}
        int[][] arr2 = new int[2][3];
//        int[][] arr3 = new int[][4];
        int[][] arr3 = new int[2][];
        for(int i = 0; i < arr1.length; ++i){
            for(int j = 0; j < arr1[i].length; ++j){
                System.out.print(arr1[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println("==========");
        for(int[] array : arr1){
            for(int x : array){
                System.out.print(x + " ");
            }
            System.out.println();
        }
        System.out.println("==========");
        String ret1 = Arrays.toString(arr1);
        String ret2 = Arrays.deepToString(arr1);
        System.out.println(ret1);
        System.out.println(ret2);

    }
    public static void main3(String[] args) {
//      数组fill equal
        int[] arr1 = {58,12,534,23,75,243,516,78,9,8,79,90,379,2369};
        int[] arr2 = {58,12,534,23,75,243,516,78,9,8,79,90,379,2369};
        System.out.println(arr1 == arr2);
        System.out.println(Arrays.equals(arr1,arr2));

        int[] arr = {58,12,534,23,75,243,516,78,9,8,79,90,379,2369};
        Arrays.fill(arr, 1,3, -1);
        System.out.println(Arrays.toString(arr));
    }
    public static void main2(String[] args) {
//        数组扩容/拷贝。
        int[] arr = {58,12,534,23,75,243,516,78,9,8,79,90,379,2369};
        int[] copy = Arrays.copyOf(arr, arr.length * 2);
        System.out.println(Arrays.toString(copy));
        copy = Arrays.copyOfRange(arr, 1, 4);
        System.out.println(Arrays.toString(copy));
    }
    public static void main1(String[] args) {
        int[] arr = {58,12,534,23,75,243,516,78,9,8,79,90,379,2369};
//        Arrays.sort(arr);
        BubbleSort(arr);
        System.out.println(Arrays.toString(arr));
        System.out.println(BinSearch(arr,0,arr.length - 1, 58));
    }
    public static void BubbleSort(int[] arr){
        for(int i = 0; i < arr.length - 1; i++) {
            boolean flag = false;
            for(int j = i + 1; j < arr.length; ++j){
                if(arr[i] > arr[j]) {
                    swap(arr, i, j);
                    flag = true;
                }
            }
            if(!flag) return;
        }
    }
    public static void swap(int[] arr,int a, int b){
        int t = arr[a];
        arr[a] = arr[b];
        arr[b] = t;
    }
    public static int BinSearch(int[] arr, int left, int right, int key){
        if(left < 0 || left > right || right >= arr.length) return -1;
        while(left <= right){
            int mid = left + ((right - left) >>> 1);
            if(arr[mid] == key) return mid;
            else if(arr[mid] < key) left = mid + 1;
            else right = mid - 1;
        }
        return -1;
    }
}
